package fy.com.controller.graph;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import fy.com.controller.base.BaseController;
import fy.com.entity.Page;
import fy.com.service.status.StatusService;
import fy.com.util.PageData;

@Controller
@RequestMapping(value="/graph")
public class GraphController extends BaseController{
	
	
	@Resource(name= "statusService")
	private StatusService statusService ;
	
	@RequestMapping(value="/graph")
	public ModelAndView graph(Page page)throws Exception{
		ModelAndView mv = this.getModelAndView();
		PageData pd=new PageData();
		pd=this.getPageData();
		page.setPd(pd);
		List<PageData> sList = statusService.list(page) ;
		List<PageData> dList=statusService.listId(pd);
		mv.addObject("pd", dList);
		mv.addObject("sList",sList);
		mv.setViewName("graph/graph");
		return mv;
	}
	
//	@RequestMapping(value="/graph")
//	public ModelAndView graph()throws Exception{
//		ModelAndView mv = this.getModelAndView();
//		PageData pd=new PageData();
//		pd=this.getPageData();
//		pd = statusService.findById(pd) ;
//		mv.addObject("pd",pd);
//		mv.setViewName("graph");
//		return mv;
//	}
	
	
	@InitBinder
	public void initBinder(WebDataBinder binder){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
	}

}

